package defectsim;

import java.util.ArrayList;
import java.util.List;

import defectsim.resources.DefectResource;
import defectsim.resources.ExternalForce;
import defectsim.resources.FrictionForce;
import defectsim.resources.InteractionForce;
import repast.simphony.context.DefaultContext;
import repast.simphony.parameter.Parameters;
import repast.simphony.util.collections.IndexedIterable;

public class DefectResourceContext extends DefaultContext<BaseAgent> {

	private SimulationEnvironment env = SimulationEnvironment.getInstance();
	
	public DefectResourceContext(String contextId){
		super(contextId, contextId);
	}
	
	public void Initialize(){
		Parameters p = env.getParameters();
		int simModel = (Integer)p.getValue("simmodel");
		switch(simModel){
		case 0: // Dislocation Dynamics (First order)
			InteractionForce intforce = InteractionForce.getInstance();
			intforce.initialize();
			this.add(intforce);
			ExternalForce extforce = ExternalForce.getInstance();
			extforce.initialize();
			this.add(extforce);
			FrictionForce fricforce = FrictionForce.getInstance();
			fricforce.initialize();
			this.add(fricforce);
			break;
		case 1: // Molecular Dynamics (Second order)
			// TODO
			break;
		}
	}
	
	public List<DefectResource> getResources(){
		List<DefectResource> resources = new ArrayList<DefectResource>();
		IndexedIterable<BaseAgent> indexedResources = this.getObjects(DefectResource.class);
		for (Object dObj : indexedResources) 
			if (dObj instanceof DefectResource){
				DefectResource r = (DefectResource)dObj;
				resources.add(r);
			}
		return resources;
	} 
}
